package com.itheima.health.service;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "检查项模块管理")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @PostMapping("checkitem/findPage")
    @ApiOperation(value = "分页查询",notes = "根据客户端请求，完成分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="currentPage",value="当前分页页码",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="queryString",value="查询条件",required=false,paramType="form",dataType="String")
    })
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        //System.out.println(queryPageBean);
        //将分页得到的数据放到Result中
        return new Result(checkItemService.findPage(queryPageBean));
    }


    @GetMapping("checkitem/findAll")
    @ApiOperation(value = "查询检查项方法", notes = "查询所有的检查项列表信息")
    public Result findAll() {
        return new Result( checkItemService.list());
    }

    //添加或者修改数据
    @PostMapping("checkitem/add")
    public Result add(@RequestBody CheckItem checkItem ){
        //boolean b = checkItemService.save(checkItem);
        boolean b = checkItemService.saveOrUpdate(checkItem);
        return new Result(b);
    }


    //逻辑删除数据
    @DeleteMapping("checkitem/deletePageById/{id}")
    public Result deletePageById(@PathVariable("id") int id){
       return new Result(checkItemService.updateItemById(id));
    }


    @PostMapping("checkitem/findPageById")
    @ApiOperation(value = "分页查询",notes = "根据客户端请求，完成分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="currentPage",value="当前分页页码",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="queryString",value="查询条件",required=false,paramType="form",dataType="String")
    })
    public Result findPageById(@RequestBody QueryPageBean queryPageBean){
        return new Result(checkItemService.findPageById(queryPageBean));
    }


    //修改单条数据
    @PostMapping("checkitem/findPageByDeId")
    public Result updatePageByDeId(CheckItem checkItem){
        checkItem.setIs_delete(0);
        //System.out.println(checkItem);
        return new Result(checkItemService.updateById(checkItem));
    }
}
